package top.ed333.mcplugins.configurableevents.handler;

import org.jetbrains.annotations.NotNull;

import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.function.Consumer;

public class Handlers implements Iterable<Handler> {
    private final List<Handler> handlers;

    public Handlers(List<Handler> handlers) {
        this.handlers = handlers;
    }

    @NotNull
    @Override
    public Iterator<Handler> iterator() {
        return new HandlersIterator(handlers);
    }

    public int size() {
        return handlers.size();
    }

    private static final class HandlersIterator implements Iterator<Handler> {
        private final List<Handler> data;
        private int index = 0;

        private HandlersIterator(List<Handler> data) {
            this.data = data;
        }

        @Override
        public boolean hasNext() {
            return index < data.size();
        }

        @Override
        public Handler next() {
            if (hasNext()) {
                return data.get(index++);
            } else {
                throw new NoSuchElementException();
            }
        }
    }
}
